//
//  MYGSystemMessageCell.swift
//  MYGrow
//
//  Created by 小火科技 on 2024/2/29.
//

import UIKit

class MYGSystemMessageCell: UITableViewCell {
    // MARK: - Property
    var model: MYGChatListCellModel? {
        didSet {
            guard let model = model else { return }
            
            logoImageView.image = UIImage(named: "Chat/Type/\(model.image)")
            nameLabel.text = model.name
            contentLabel.text = model.content
        }
    }
    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        contentView.backgroundColor = .rgba(250, 250, 250, 1)
        contentView.addSubview(mainView)
        mainView.addSubview(logoImageView)
        mainView.addSubview(nameLabel)
        mainView.addSubview(timeLabel)
        mainView.addSubview(contentLabel)
        
        mainView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(16)
            make.top.equalToSuperview()
            make.bottom.equalToSuperview().inset(14)
        }
        
        logoImageView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(17)
            make.top.equalToSuperview().offset(15)
            make.width.height.equalTo(40)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(logoImageView.snp.right).offset(13)
            make.top.equalTo(logoImageView.snp.top)
        }
        
        timeLabel.snp.makeConstraints { make in
            make.right.equalToSuperview().inset(8)
            make.centerY.equalTo(nameLabel)
        }
        
        contentLabel.snp.makeConstraints { make in
            make.left.equalTo(logoImageView.snp.right).offset(13)
            make.right.equalToSuperview().inset(24)
            make.top.equalTo(nameLabel.snp.bottom).offset(2)
            make.bottom.equalToSuperview().inset(12)
        }
    }
    // MARK: - lazy load
    private lazy var mainView: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        view.layer.masksToBounds = true
        view.layer.cornerRadius = 10
        return view
    }()
    private lazy var logoImageView: UIImageView = {
        let imgV = UIImageView()
        imgV.layer.masksToBounds = true
        imgV.layer.cornerRadius = 20
        return imgV
    }()
    
    private lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(16)
        label.textColor = .rgba(44, 44, 44, 1)
        return label
    }()
    
    private lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.textColor = .rgba(88, 88, 88, 1)
        label.font = .regular(13)
        label.numberOfLines = 2
        return label
    }()
    
    private lazy var timeLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(13)
        label.textColor = .rgba(88, 88, 88, 1)
        return label
    }()
}
